package com.huangpuweb.task.controller;

import com.huangpuweb.task.model.*;
import com.huangpuweb.task.service.HiveZdk57ApiService;
import com.huangpuweb.task.service.SyncSysDataService;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
public class HpBlmq57From80Job {
    @Resource
    private HiveZdk57ApiService hiveZdk57ApiService;
    @Resource
    private SyncSysDataService syncSysDataService;

    public void hpBlmq57From80JobTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------HpBlmq57From80JobTask----------" + new Date());
        List<BlmqBuildInfo> blmqBuildInfoList = hiveZdk57ApiService.getBuildInfo();
        if (blmqBuildInfoList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------buildInfo空----------" + new Date());
        } else {
            for (BlmqBuildInfo blmqBuildInfo : blmqBuildInfoList) {
                BlmqBuildInfo info = syncSysDataService.findById(blmqBuildInfo.getBUILD_ID());
                if (info == null) {
                    syncSysDataService.insertBulidInfo(blmqBuildInfo);
                } else {
                    syncSysDataService.updateBulidInfo(blmqBuildInfo);
                }
            }
        }

    }

    public void hpCheckListTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListTask----------" + new Date());
        List<BlmqCheckList> checkListList = hiveZdk57ApiService.hpCheckListTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListTask空----------" + new Date());
        } else {
            for (BlmqCheckList blmqCheckList : checkListList) {
                BlmqCheckList info = syncSysDataService.findCheckListById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertCheckListBulidInfo(blmqCheckList);
                } else {
                    syncSysDataService.updateCheckListBulidInfo(blmqCheckList);
                }
            }
        }
    }

    public void hpCheckListDtlTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListDtlTask----------" + new Date());
        List<BlmqCheckListDtl> checkListList = hiveZdk57ApiService.hpCheckListDtlTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListDtlTask空----------" + new Date());

        } else {
            for (BlmqCheckListDtl blmqCheckList : checkListList) {
                BlmqCheckListDtl info = syncSysDataService.findCheckListDtlById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertCheckListDtlBulidInfo(blmqCheckList);
                } else {
                    syncSysDataService.updateCheckListDtlBulidInfo(blmqCheckList);
                }
            }
        }
    }

    public void hpCheckListLogTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListLogTask----------" + new Date());
        List<BlmqCheckListLog> checkListList = hiveZdk57ApiService.hpCheckListLogTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------HpCheckListLogTask空----------" + new Date());

        } else {
            for (BlmqCheckListLog blmqCheckList : checkListList) {
                BlmqCheckListLog info = syncSysDataService.findCheckListLogById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertCheckListLogBulidInfo(blmqCheckList);
                } else {
                    syncSysDataService.updateCheckListLogBulidInfo(blmqCheckList);
                }
            }
        }
    }

    public void hpCountyCheckCountTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------hpCountyCheckCountTask----------" + new Date());
        List<BlmqCountryCheck> checkListList = hiveZdk57ApiService.hpCountyCheckCountTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------hpCountyCheckCountTask空----------" + new Date());

        } else {
            for (BlmqCountryCheck blmqCheckList : checkListList) {
                BlmqCountryCheck info = syncSysDataService.findBlmqCountryCheckById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertBlmqCountryCheck(blmqCheckList);
                } else {
                    syncSysDataService.updateBlmqCountryCheck(blmqCheckList);
                }
            }
        }
    }

    public void emergencyDtlTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------emergencyDtlTask----------" + new Date());
        List<BlmqEmergencyDtl> checkListList = hiveZdk57ApiService.emergencyDtlTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------emergencyDtlTask空----------" + new Date());

        } else {
            for (BlmqEmergencyDtl blmqCheckList : checkListList) {
                BlmqEmergencyDtl info = syncSysDataService.findBlmqEmergencyDtlById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertBlmqEmergencyDtl(blmqCheckList);
                } else {
                    syncSysDataService.updateBlmqEmergencyDtl(blmqCheckList);
                }
            }
        }
    }

    public void ownweCheckListTask() {
        LogFactory.getLog(this.getClass()).info("--------start-------ownweCheckListTask----------" + new Date());
        List<BlmqOwnCheckList> checkListList = hiveZdk57ApiService.ownweCheckListTask();
        if (checkListList.isEmpty()) {
            LogFactory.getLog(this.getClass()).info("--------start-------ownweCheckListTask空----------" + new Date());
        } else {
            for (BlmqOwnCheckList blmqCheckList : checkListList) {
                BlmqOwnCheckList info = syncSysDataService.findBlmqOwnCheckListById(blmqCheckList.getID());
                if (info == null) {
                    syncSysDataService.insertBlmqOwnCheckList(blmqCheckList);
                } else {
                    syncSysDataService.updateBlmqOwnCheckList(blmqCheckList);
                }
            }
        }
    }

}
